package com.li.onjava8.concurrent.es;

import com.li.onjava8.concurrent.es.task.NapTask;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.stream.IntStream;

/**
 * @author li
 * @date 2023/10/30 14:15
 */
public class CachedThreadPool {
    public static void main(String[] args) {
        //每个任务都有自己的线程，所以它们都并行运行
        ExecutorService es = Executors.newCachedThreadPool();
        IntStream.range(0, 10)
                .mapToObj(NapTask::new)
                .forEach(es::execute);
        es.shutdown();
    }
}
